﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using DelonixRegiaHotel.Classes;

namespace DelonixRegiaHotel.DBManager
{
    class ReportDBManager
    {
        public static int getNoRoomStatus()
        {
            int result = 0;
            SqlConnection conn = new SqlConnection();

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();

                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "SELECT COUNT(roomStatus) FROM CheckInOut Where roomStatus = 'CheckIn'";
                result = (Int32)comm.ExecuteScalar();
            }
            catch (SqlException e)
            {
                throw e;
            }
            return result;
        }

        
        public static int InsertRoomOccupancy(RoomOccupancy r)
        {
            int insertRow = 0;
            SqlConnection conn = new SqlConnection();

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();

                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "INSERT INTO RoomOccupancy VALUES (@roomOccupancy)";

                comm.Parameters.AddWithValue("@roomOccupancy", r.RoomOccupan);
                insertRow = comm.ExecuteNonQuery();
                conn.Close();
            }
            catch (SqlException e)
            {
                throw e;
            }
            return insertRow;
        }

        public static ArrayList getStaffShiftDay(Staff sta)
        {
            ArrayList result = new ArrayList();
            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                conn.Open();

                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "SELECT shiftDay FROM Staff WHERE shiftDay = @shiftDay";
                comm.Parameters.AddWithValue("@shiftDay", sta);

                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Staff s = new Staff();
                    s.ShiftDay = (string)dr["shiftDay"];
                }

            }
            catch (SqlException e)
            {
                throw e;
            }
            return result;
        }
    }
}
